package com.justech.eat.entity;

import com.justech.common.util.DateUtil;
import com.justech.common.vo.PageVo;
import lombok.*;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

/**
 * @program: eat-service
 * @description: 订单.
 * 在关系型数据库的设计中，{@link Order}和{@link OrderDetail}是一对多的关系。
 * @author: feifei.li
 * @create: 2020-05-21 17:23
 **/
@Table(name = "e_order")
@Entity
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class Order extends PageVo {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private String jobNumber;

    private String date;

    private String deviceInfo;

    private Date createTime;

    private Date updateTime;

    @Transient
    private String userName;

    @Transient
    private String deptName;

    @OneToMany(mappedBy = "orderId", fetch = FetchType.EAGER)
    private List<OrderDetail> orderDetails;

    public static Order build(String jobNumber, String date) {
        Order order = new Order();
        order.setDate(date);
        order.setJobNumber(jobNumber);
        order.setDeviceInfo("");
        order.setCreateTime(DateUtil.now());
        return order;
    }


}
